﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcmyjobs.Web.links
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["adminName"] != null)
                {
                    if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                    {
                        int lin = (Convert.ToInt32(Request.Params["id"]));
                        ShowInfo(lin);
                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='../adminlogin2.aspx'");
                }

            }
        }

        private void ShowInfo(int lin)
        {
            lcmyjobs.BLL.links bll = new lcmyjobs.BLL.links();
            lcmyjobs.Model.links model = bll.GetModel(lin);
            this.lbllin.Text = model.lin.ToString();
            this.txtltext.Text = model.ltext;
            this.txtllink.Text = model.llink;
            this.txtrank.Text = model.rank.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtltext.Text.Trim().Length == 0)
            {
                strErr += "文本不能为空！\\n";
            }
            if (this.txtllink.Text.Trim().Length == 0)
            {
                strErr += "链接地址不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtrank.Text))
            {
                strErr += "位置数格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int lin = int.Parse(this.lbllin.Text);
            string ltext = this.txtltext.Text;
            string llink = this.txtllink.Text;
            int rank = int.Parse(this.txtrank.Text);


            lcmyjobs.Model.links model = new lcmyjobs.Model.links();
            model.lin = lin;
            model.ltext = ltext;
            model.llink = llink;
            model.rank = rank;

            lcmyjobs.BLL.links bll = new lcmyjobs.BLL.links();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
